﻿
// This file implements the TableControl, TableControlRow, and RecordControl classes for the 
// EditTipo_GasolinaTable.aspx page.  The Row or RecordControl classes are the 
// ideal place to add code customizations. For example, you can override the LoadData, 
// CreateWhereClause, DataBind, SaveData, GetUIData, and Validate methods.

#region "Using statements"    

using Microsoft.VisualBasic;
using BaseClasses.Web.UI.WebControls;
using System;
using System.Collections;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseClasses;
using BaseClasses.Data;
using BaseClasses.Utils;
using ReportTools.ReportCreator;
using ReportTools.Shared;

        
using EnGasAdoAPP.Business;
using EnGasAdoAPP.Data;
using EnGasAdoAPP.UI;
using EnGasAdoAPP;
		

#endregion

  
namespace EnGasAdoAPP.UI.Controls.EditTipo_GasolinaTable
{
  

#region "Section 1: Place your customizations here."

    
public class Tipo_GasolinaTableControlRow : BaseTipo_GasolinaTableControlRow
{
      
        // The BaseTipo_GasolinaTableControlRow implements code for a ROW within the
        // the Tipo_GasolinaTableControl table.  The BaseTipo_GasolinaTableControlRow implements the DataBind and SaveData methods.
        // The loading of data is actually performed by the LoadData method in the base class of Tipo_GasolinaTableControl.

        // This is the ideal place to add your code customizations. For example, you can override the DataBind, 
        // SaveData, GetUIData, and Validate methods.
        
}

  

public class Tipo_GasolinaTableControl : BaseTipo_GasolinaTableControl
{
    // The BaseTipo_GasolinaTableControl class implements the LoadData, DataBind, CreateWhereClause
    // and other methods to load and display the data in a table control.

    // This is the ideal place to add your code customizations. You can override the LoadData and CreateWhereClause,
    // The Tipo_GasolinaTableControlRow class offers another place where you can customize
    // the DataBind, GetUIData, SaveData and Validate methods specific to each row displayed on the table.

}

  

#endregion

  

#region "Section 2: Do not modify this section."
    
    
// Base class for the Tipo_GasolinaTableControlRow control on the EditTipo_GasolinaTable page.
// Do not modify this class. Instead override any method in Tipo_GasolinaTableControlRow.
public class BaseTipo_GasolinaTableControlRow : EnGasAdoAPP.UI.BaseApplicationRecordControl
{
        public BaseTipo_GasolinaTableControlRow()
        {
            this.Init += Control_Init;
            this.Load += Control_Load;
            this.PreRender += Control_PreRender;
            this.EvaluateFormulaDelegate = new DataSource.EvaluateFormulaDelegate(this.EvaluateFormula);
        }

        // To customize, override this method in Tipo_GasolinaTableControlRow.
        protected virtual void Control_Init(object sender, System.EventArgs e)
        {
                
            this.ClearControlsFromSession();
        }

        // To customize, override this method in Tipo_GasolinaTableControlRow.
        protected virtual void Control_Load(object sender, System.EventArgs e)
        {
        
            //Call LoadFocusScripts from repeater so that onfocus attribute could be added to elements
            this.Page.LoadFocusScripts(this);
        
              // Show confirmation message on Click
              this.Tipo_GasolinaRowDeleteButton.Attributes.Add("onClick", "return (confirm('" + ((BaseApplicationPage)this.Page).GetResourceValue("DeleteRecordConfirm", "EnGasAdoAPP") + "'));");   
        
            // Register the event handlers.
          
              this.Tipo_GasolinaRowDeleteButton.Click += new ImageClickEventHandler(Tipo_GasolinaRowDeleteButton_Click);
        
              this.Tipo_GasolinaRowEditButton.Click += new ImageClickEventHandler(Tipo_GasolinaRowEditButton_Click);
        
              this.Tipo_GasolinaRowViewButton.Click += new ImageClickEventHandler(Tipo_GasolinaRowViewButton_Click);
        
              this.descripcion.TextChanged += descripcion_TextChanged;
            
              this.Nombre_Tipo_Gasolina.TextChanged += Nombre_Tipo_Gasolina_TextChanged;
            
        }

        public virtual void LoadData()  
        {
            // Load the data from the database into the DataSource Tipo_Gasolina record.
            // It is better to make changes to functions called by LoadData such as
            // CreateWhereClause, rather than making changes here.
            
        
            // The RecordUniqueId is set the first time a record is loaded, and is
            // used during a PostBack to load the record.
            if (this.RecordUniqueId != null && this.RecordUniqueId.Length > 0) {
              
                this.DataSource = Tipo_GasolinaTable.GetRecord(this.RecordUniqueId, true);
              
                return;
            }
      
            // Since this is a row in the table, the data for this row is loaded by the 
            // LoadData method of the BaseTipo_GasolinaTableControl when the data for the entire
            // table is loaded.
            
            this.DataSource = new Tipo_GasolinaRecord();
            
        }

        public override void DataBind()
        {
            // The DataBind method binds the user interface controls to the values
            // from the database record.  To do this, it calls the Set methods for 
            // each of the field displayed on the webpage.  It is better to make 
            // changes in the Set methods, rather than making changes here.
            
            base.DataBind();
            
            // Make sure that the DataSource is initialized.
            
            if (this.DataSource == null) {
                return;
            }
              
    
            // LoadData for DataSource for chart and report if they exist
          

            // Call the Set methods for each controls on the panel
        
                Setdescripcion();
                SetNombre_Tipo_Gasolina();
                
                
                
                

      

            this.IsNewRecord = true;
          
            if (this.DataSource.IsCreated) {
                this.IsNewRecord = false;
              
                this.RecordUniqueId = this.DataSource.GetID().ToXmlString();
            }
          

            // Now load data for each record and table child UI controls.
            // Ordering is important because child controls get 
            // their parent ids from their parent UI controls.
            bool shouldResetControl = false;
            if (shouldResetControl) { }; // prototype usage to void compiler warnings
            
        }

        
        public virtual void Setdescripcion()
        {
            
            // If data was retrieved from UI previously, restore it
            if (this.PreviousUIData.ContainsKey(this.descripcion.ID))
            {
            
                this.descripcion.Text = this.PreviousUIData[this.descripcion.ID].ToString();
              
                return;
            }
            
                    
            // Set the descripcion TextBox on the webpage with value from the
            // Tipo_Gasolina database record.

            // this.DataSource is the Tipo_Gasolina record retrieved from the database.
            // this.descripcion is the ASP:TextBox on the webpage.
                  
            if (this.DataSource != null && this.DataSource.descripcionSpecified) {
                								
                // If the descripcion is non-NULL, then format the value.
                // The Format method will use the Display Format
                                  string formattedValue = this.DataSource.Format(Tipo_GasolinaTable.descripcion);
                                
                this.descripcion.Text = formattedValue;
                   
            } 
            
            else {
            
                // descripcion is NULL in the database, so use the Default Value.  
                // Default Value could also be NULL.
        
                this.descripcion.Text = Tipo_GasolinaTable.descripcion.Format(Tipo_GasolinaTable.descripcion.DefaultValue);
            		
            }
            
        }
                
        public virtual void SetNombre_Tipo_Gasolina()
        {
            
            // If data was retrieved from UI previously, restore it
            if (this.PreviousUIData.ContainsKey(this.Nombre_Tipo_Gasolina.ID))
            {
            
                this.Nombre_Tipo_Gasolina.Text = this.PreviousUIData[this.Nombre_Tipo_Gasolina.ID].ToString();
              
                return;
            }
            
                    
            // Set the Nombre_Tipo_Gasolina TextBox on the webpage with value from the
            // Tipo_Gasolina database record.

            // this.DataSource is the Tipo_Gasolina record retrieved from the database.
            // this.Nombre_Tipo_Gasolina is the ASP:TextBox on the webpage.
                  
            if (this.DataSource != null && this.DataSource.Nombre_Tipo_GasolinaSpecified) {
                								
                // If the Nombre_Tipo_Gasolina is non-NULL, then format the value.
                // The Format method will use the Display Format
                                  string formattedValue = this.DataSource.Format(Tipo_GasolinaTable.Nombre_Tipo_Gasolina);
                                
                this.Nombre_Tipo_Gasolina.Text = formattedValue;
                   
            } 
            
            else {
            
                // Nombre_Tipo_Gasolina is NULL in the database, so use the Default Value.  
                // Default Value could also be NULL.
        
                this.Nombre_Tipo_Gasolina.Text = Tipo_GasolinaTable.Nombre_Tipo_Gasolina.Format(Tipo_GasolinaTable.Nombre_Tipo_Gasolina.DefaultValue);
            		
            }
            
        }
                
        public BaseClasses.Data.DataSource.EvaluateFormulaDelegate EvaluateFormulaDelegate;

        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, string format, System.Collections.Generic.IDictionary<string, object> variables, bool includeDS, FormulaEvaluator e)
        {
            if (e == null)
                e = new FormulaEvaluator();

            e.Variables.Clear();
            // add variables for formula evaluation
            if (variables != null)
            {
                System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<string, object>> enumerator = variables.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    e.Variables.Add(enumerator.Current.Key, enumerator.Current.Value);
                }
            }
            
            
            if (includeDS)
            {
                
            }
            
            // All variables referred to in the formula are expected to be
            // properties of the DataSource.  For example, referring to
            // UnitPrice as a variable will refer to DataSource.UnitPrice
            if (dataSourceForEvaluate == null)
                e.DataSource = this.DataSource;
            else
                e.DataSource = dataSourceForEvaluate;

            // Define the calling control.  This is used to add other 
            // related table and record controls as variables.
            e.CallingControl = this;

            object resultObj = e.Evaluate(formula);
            if (resultObj == null)
                return "";
            
            if ( !string.IsNullOrEmpty(format) && (string.IsNullOrEmpty(formula) || formula.IndexOf("Format(") < 0) )
                return FormulaUtils.Format(resultObj, format);
            else
                return resultObj.ToString();
        }
                
        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, string format, System.Collections.Generic.IDictionary<string, object> variables, bool includeDS)
        {
          return EvaluateFormula(formula, dataSourceForEvaluate, format, variables, includeDS, null);
        }

        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, string format, System.Collections.Generic.IDictionary<string, object> variables)
        {
          return EvaluateFormula(formula, dataSourceForEvaluate, format, variables, true, null);
        }

        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, string format)
        {
          return this.EvaluateFormula(formula, dataSourceForEvaluate, format, null, true, null);
        }

        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, System.Collections.Generic.IDictionary<string, object> variables, FormulaEvaluator e)
        {
          return this.EvaluateFormula(formula, dataSourceForEvaluate, null, variables, true, e);
        }

        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate)
        {
          return this.EvaluateFormula(formula, dataSourceForEvaluate, null, null, true, null);
        }

        public virtual string EvaluateFormula(string formula, bool includeDS)
        {
          return this.EvaluateFormula(formula, null, null, null, includeDS, null);
        }

        public virtual string EvaluateFormula(string formula)
        {
          return this.EvaluateFormula(formula, null, null, null, true, null);
        }
        
      

        public virtual void RegisterPostback()
        {
            
        }
    
        

        public virtual void SaveData()
        {
            // Saves the associated record in the database.
            // SaveData calls Validate and Get methods - so it may be more appropriate to
            // customize those methods.

            // 1. Load the existing record from the database. Since we save the entire record, this ensures 
            // that fields that are not displayed are also properly initialized.
            this.LoadData();
        
          
            // 2. Perform any custom validation.
            this.Validate();

            
            // 3. Set the values in the record with data from UI controls.
            // This calls the Get() method for each of the user interface controls.
            this.GetUIData();
   
            // 4. Save in the database.
            // We should not save the record if the data did not change. This
            // will save a database hit and avoid triggering any database triggers.
            
            if (this.DataSource.IsAnyValueChanged) {
                // Save record to database but do not commit yet.
                // Auto generated ids are available after saving for use by child (dependent) records.
                this.DataSource.Save();
                
                // Set the DataChanged flag to True for the for the related panels so they get refreshed as well.
                ((Tipo_GasolinaTableControl)MiscUtils.GetParentControlObject(this, "Tipo_GasolinaTableControl")).DataChanged = true;
                ((Tipo_GasolinaTableControl)MiscUtils.GetParentControlObject(this, "Tipo_GasolinaTableControl")).ResetData = true;
            }
            
      
            // update session or cookie by formula
             		  
      
            // Setting the DataChanged to True results in the page being refreshed with
            // the most recent data from the database.  This happens in PreRender event
            // based on the current sort, search and filter criteria.
            this.DataChanged = true;
            this.ResetData = true;
            
            // For Master-Detail relationships, save data on the Detail table(s)
              
        }

        public virtual void GetUIData()
        {
            // The GetUIData method retrieves the updated values from the user interface 
            // controls into a database record in preparation for saving or updating.
            // To do this, it calls the Get methods for each of the field displayed on 
            // the webpage.  It is better to make changes in the Get methods, rather 
            // than making changes here.
      
            // Call the Get methods for each of the user interface controls.
        
            Getdescripcion();
            GetNombre_Tipo_Gasolina();
        }
        
        
        public virtual void Getdescripcion()
        {
            
            // Retrieve the value entered by the user on the descripcion ASP:TextBox, and
            // save it into the descripcion field in DataSource Tipo_Gasolina record.
            
            // Custom validation should be performed in Validate, not here.
                    
            // Save the value to data source
            
            this.DataSource.Parse(this.descripcion.Text, Tipo_GasolinaTable.descripcion);							
            
        }
                
        public virtual void GetNombre_Tipo_Gasolina()
        {
            
            // Retrieve the value entered by the user on the Nombre_Tipo_Gasolina ASP:TextBox, and
            // save it into the Nombre_Tipo_Gasolina field in DataSource Tipo_Gasolina record.
            
            // Custom validation should be performed in Validate, not here.
                    
            // Save the value to data source
            
            this.DataSource.Parse(this.Nombre_Tipo_Gasolina.Text, Tipo_GasolinaTable.Nombre_Tipo_Gasolina);							
            
        }
                

      // To customize, override this method in Tipo_GasolinaTableControlRow.
      
        public virtual WhereClause CreateWhereClause()
         
        {
        
            return null;
        
        }
        
        
    
        public virtual void Validate()
        {
            // Add custom validation for any control within this panel.
            // Example.  If you have a State ASP:Textbox control
            // if (this.State.Text != "CA")
            //    throw new Exception("State must be CA (California).");
            // The Validate method is common across all controls within
            // this panel so you can validate multiple fields, but report
            // one error message.
            
            
            
        }

        public virtual void Delete()
        {
        
            if (this.IsNewRecord) {
                return;
            }

            KeyValue pkValue = KeyValue.XmlToKey(this.RecordUniqueId);
          Tipo_GasolinaTable.DeleteRecord(pkValue);
          
              
            // Setting the DataChanged to True results in the page being refreshed with
            // the most recent data from the database.  This happens in PreRender event
            // based on the current sort, search and filter criteria.
            ((Tipo_GasolinaTableControl)MiscUtils.GetParentControlObject(this, "Tipo_GasolinaTableControl")).DataChanged = true;
            ((Tipo_GasolinaTableControl)MiscUtils.GetParentControlObject(this, "Tipo_GasolinaTableControl")).ResetData = true;
        }

        protected virtual void Control_PreRender(object sender, System.EventArgs e)
        {
            // PreRender event is raised just before page is being displayed.
            try {
                DbUtils.StartTransaction();
                this.RegisterPostback();
                if (!this.Page.ErrorOnPage && (this.Page.IsPageRefresh || this.DataChanged || this.ResetData)) {
                  
                
                    // Re-load the data and update the web page if necessary.
                    // This is typically done during a postback (filter, search button, sort, pagination button).
                    // In each of the other click handlers, simply set DataChanged to True to reload the data.
                    this.LoadData();
                    this.DataBind();
                }
                				
            } catch (Exception ex) {
                BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
            } finally {
                DbUtils.EndTransaction();
            }
        }
        
            
        protected override void SaveControlsToSession()
        {
            base.SaveControlsToSession();
        
    
            // Save pagination state to session.
          
        }
        
        
    
        protected override void ClearControlsFromSession()
        {
            base.ClearControlsFromSession();

        

            // Clear pagination state from session.
        
        }
        
        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);
            string isNewRecord = (string)ViewState["IsNewRecord"];
            if (isNewRecord != null && isNewRecord.Length > 0) {
                this.IsNewRecord = Boolean.Parse(isNewRecord);
            }
        
            string myCheckSum = (string)ViewState["CheckSum"];
            if (myCheckSum != null && myCheckSum.Length > 0) {
                this.CheckSum = myCheckSum;
            }
        
    
            // Load view state for pagination control.
                 
        }

        protected override object SaveViewState()
        {
            ViewState["IsNewRecord"] = this.IsNewRecord.ToString();
            ViewState["CheckSum"] = this.CheckSum;
        

            // Load view state for pagination control.
               
            return base.SaveViewState();
        }

        
        // Event handler for ImageButton .
        public virtual void Tipo_GasolinaRowDeleteButton_Click(object sender, ImageClickEventArgs args)
        {
        
            try {
                // Enclose all database retrieval/update code within a Transaction boundary
                DbUtils.StartTransaction();
                
            if (!this.Page.IsPageRefresh) {
        Tipo_GasolinaTableControl tc= ((Tipo_GasolinaTableControl)MiscUtils.GetParentControlObject(this, "Tipo_GasolinaTableControl"));
                if (tc != null){
                    if (!this.IsNewRecord){
                        tc.AddToDeletedRecordIds((Tipo_GasolinaTableControlRow)this);
                    }
                    this.Visible = false;
                    tc.SetFormulaControls();                    
                }
              
            }
      
            } catch (Exception ex) {
                  // Upon error, rollback the transaction
                  this.Page.RollBackTransaction(sender);
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
                DbUtils.EndTransaction();
            }
    
        }
        
        // Event handler for ImageButton .
        public virtual void Tipo_GasolinaRowEditButton_Click(object sender, ImageClickEventArgs args)
        {
        
            // The redirect URL is set on the Properties, Custom Properties or Actions.
            // The ModifyRedirectURL call resolves the parameters before the
            // Response.Redirect redirects the page to the URL.  
            // Any code after the Response.Redirect call will not be executed, since the page is
            // redirected to the URL.
            
          string url = @"../Tipo_Gasolina/EditTipo_Gasolina.aspx?Tipo_Gasolina={PK}";
        
        bool shouldRedirect = true;
        string TargetKey = null;
        string DFKA = TargetKey;
        string id = DFKA;
        string value = id;
      
            try {
                // Enclose all database retrieval/update code within a Transaction boundary
                DbUtils.StartTransaction();
                
                url = this.ModifyRedirectUrl(url, "",false);
                url = this.Page.ModifyRedirectUrl(url, "",false);
              
            } catch (Exception ex) {
                  // Upon error, rollback the transaction
                  this.Page.RollBackTransaction(sender);
                  shouldRedirect = false;
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
                DbUtils.EndTransaction();
            }
            if (shouldRedirect) {
                this.Page.ShouldSaveControlsToSession = true;
                this.Page.Response.Redirect(url);
            }
        
            else if (TargetKey != null && !shouldRedirect){
            this.Page.ShouldSaveControlsToSession = true ; 
            this.Page.CloseWindow(true);
            }
        
        }
        
        // Event handler for ImageButton .
        public virtual void Tipo_GasolinaRowViewButton_Click(object sender, ImageClickEventArgs args)
        {
        
            // The redirect URL is set on the Properties, Custom Properties or Actions.
            // The ModifyRedirectURL call resolves the parameters before the
            // Response.Redirect redirects the page to the URL.  
            // Any code after the Response.Redirect call will not be executed, since the page is
            // redirected to the URL.
            
          string url = @"../Tipo_Gasolina/ShowTipo_Gasolina.aspx?Tipo_Gasolina={PK}";
        
        bool shouldRedirect = true;
        string TargetKey = null;
        string DFKA = TargetKey;
        string id = DFKA;
        string value = id;
      
            try {
                // Enclose all database retrieval/update code within a Transaction boundary
                DbUtils.StartTransaction();
                
                url = this.ModifyRedirectUrl(url, "",false);
                url = this.Page.ModifyRedirectUrl(url, "",false);
              
            } catch (Exception ex) {
                  // Upon error, rollback the transaction
                  this.Page.RollBackTransaction(sender);
                  shouldRedirect = false;
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
                DbUtils.EndTransaction();
            }
            if (shouldRedirect) {
                this.Page.ShouldSaveControlsToSession = true;
                this.Page.Response.Redirect(url);
            }
        
            else if (TargetKey != null && !shouldRedirect){
            this.Page.ShouldSaveControlsToSession = true ; 
            this.Page.CloseWindow(true);
            }
        
        }
        
        protected virtual void descripcion_TextChanged(object sender, EventArgs args)
        {
                    
              }
            
        protected virtual void Nombre_Tipo_Gasolina_TextChanged(object sender, EventArgs args)
        {
                    
              }
            
  
        private Hashtable _PreviousUIData = new Hashtable();
        public virtual Hashtable PreviousUIData {
            get {
                return this._PreviousUIData;
            }
            set {
                this._PreviousUIData = value;
            }
        }
  
        private bool _IsNewRecord = true;
        public virtual bool IsNewRecord {
            get {
                return this._IsNewRecord;
            }
            set {
                this._IsNewRecord = value;
            }
        }

        private bool _DataChanged = false;
        public virtual bool DataChanged {
            get {
                return this._DataChanged;
            }
            set {
                this._DataChanged = value;
            }
        }

        private bool _ResetData = false;
        public virtual bool ResetData {
            get {
                return (this._ResetData);
            }
            set {
                this._ResetData = value;
            }
        }
        
        public String RecordUniqueId {
            get {
                return (string)this.ViewState["BaseTipo_GasolinaTableControlRow_Rec"];
            }
            set {
                this.ViewState["BaseTipo_GasolinaTableControlRow_Rec"] = value;
            }
        }
        
        private Tipo_GasolinaRecord _DataSource;
        public Tipo_GasolinaRecord DataSource {
             
            get {
                return (this._DataSource);
            }
            set {
                this._DataSource = value;
            }
        }
        
        

        private string _checkSum;
        public virtual string CheckSum {
            get {
                return (this._checkSum);
            }
            set {
                this._checkSum = value;
            }
        }
    
        private int _TotalPages;
        public virtual int TotalPages {
            get {
                return (this._TotalPages);
            }
            set {
                this._TotalPages = value;
            }
        }
        
        private int _PageIndex;
        public virtual int PageIndex {
            get {
                return (this._PageIndex);
            }
            set {
                this._PageIndex = value;
            }
        }
        
        private bool _DisplayLastPage;
        public virtual bool DisplayLastPage {
            get {
                return (this._DisplayLastPage);
            }
            set {
                this._DisplayLastPage = value;
            }
        }
        
        
    
        private KeyValue selectedParentKeyValue;
        public KeyValue SelectedParentKeyValue
        {
            get
            {
                return this.selectedParentKeyValue;
            }
            set
            {
                this.selectedParentKeyValue = value;
            }
        }
       
#region "Helper Properties"
        
        public System.Web.UI.WebControls.TextBox descripcion {
            get {
                return (System.Web.UI.WebControls.TextBox)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "descripcion");
            }
        }
            
        public System.Web.UI.WebControls.TextBox Nombre_Tipo_Gasolina {
            get {
                return (System.Web.UI.WebControls.TextBox)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Nombre_Tipo_Gasolina");
            }
        }
            
        public System.Web.UI.WebControls.CheckBox Tipo_GasolinaRecordRowSelection {
            get {
                return (System.Web.UI.WebControls.CheckBox)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Tipo_GasolinaRecordRowSelection");
            }
        }
        
        public System.Web.UI.WebControls.ImageButton Tipo_GasolinaRowDeleteButton {
            get {
                return (System.Web.UI.WebControls.ImageButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Tipo_GasolinaRowDeleteButton");
            }
        }
        
        public System.Web.UI.WebControls.ImageButton Tipo_GasolinaRowEditButton {
            get {
                return (System.Web.UI.WebControls.ImageButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Tipo_GasolinaRowEditButton");
            }
        }
        
        public System.Web.UI.WebControls.ImageButton Tipo_GasolinaRowViewButton {
            get {
                return (System.Web.UI.WebControls.ImageButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Tipo_GasolinaRowViewButton");
            }
        }
        
#endregion

#region "Helper Functions"
        public override string ModifyRedirectUrl(string url, string arg, bool bEncrypt)
        {
            return this.Page.EvaluateExpressions(url, arg, bEncrypt, this);
        }

        public override string EvaluateExpressions(string url, string arg, bool bEncrypt)
        {
        Tipo_GasolinaRecord rec = null;
             
            try {
                rec = this.GetRecord();
            }
            catch (Exception ) {
                // Do Nothing
            }
            
            if (rec == null && url.IndexOf("{") >= 0) {
                // Localization.
                
                throw new Exception(Page.GetResourceValue("Err:RecDataSrcNotInitialized", "EnGasAdoAPP"));
                    
            }
        
            return EvaluateExpressions(url, arg, rec, bEncrypt);
             
        }

        
        public virtual Tipo_GasolinaRecord GetRecord()
             
        {
        
            if (this.DataSource != null) {
                return this.DataSource;
            }
            
            if (this.RecordUniqueId != null) {
              
                return Tipo_GasolinaTable.GetRecord(this.RecordUniqueId, true);
              
            }
            
            // Localization.
            
            throw new Exception(Page.GetResourceValue("Err:RetrieveRec", "EnGasAdoAPP"));
                
        }

        public new BaseApplicationPage Page
        {
            get {
                return ((BaseApplicationPage)base.Page);
            }
        }

#endregion

}

  
// Base class for the Tipo_GasolinaTableControl control on the EditTipo_GasolinaTable page.
// Do not modify this class. Instead override any method in Tipo_GasolinaTableControl.
public class BaseTipo_GasolinaTableControl : EnGasAdoAPP.UI.BaseApplicationTableControl
{
         

       public BaseTipo_GasolinaTableControl()
        {
            this.Init += Control_Init;
            this.Load += Control_Load;
            this.PreRender += Control_PreRender;
            this.EvaluateFormulaDelegate = new DataSource.EvaluateFormulaDelegate(this.EvaluateFormula);
        }

        protected virtual void Control_Init(object sender, System.EventArgs e)
        {
          
 
            // Setup the filter and search events.
        
            this.descripcionFilter.SelectedIndexChanged += new EventHandler(descripcionFilter_SelectedIndexChanged);
            this.Nombre_Tipo_GasolinaFilter.SelectedIndexChanged += new EventHandler(Nombre_Tipo_GasolinaFilter_SelectedIndexChanged);
            if (!this.Page.IsPostBack)
            {
                string initialVal = "";
                if  (this.InSession(this.descripcionFilter)) 				
                    initialVal = this.GetFromSession(this.descripcionFilter);
                
                else
                    
                    initialVal = EvaluateFormula("URL(\"descripcion\")");
                
                if (initialVal != null && initialVal != "")		
                {
                        
                    this.descripcionFilter.Items.Add(new ListItem(initialVal, initialVal));
                        
                    this.descripcionFilter.SelectedValue = initialVal;
                            
                    }
            }
            if (!this.Page.IsPostBack)
            {
                string initialVal = "";
                if  (this.InSession(this.Nombre_Tipo_GasolinaFilter)) 				
                    initialVal = this.GetFromSession(this.Nombre_Tipo_GasolinaFilter);
                
                else
                    
                    initialVal = EvaluateFormula("URL(\"Nombre_Tipo_Gasolina\")");
                
                if (initialVal != null && initialVal != "")		
                {
                        
                    this.Nombre_Tipo_GasolinaFilter.Items.Add(new ListItem(initialVal, initialVal));
                        
                    this.Nombre_Tipo_GasolinaFilter.SelectedValue = initialVal;
                            
                    }
            }
            if (!this.Page.IsPostBack)
            {
                string initialVal = "";
                if  (this.InSession(this.Tipo_GasolinaSearch)) 				
                    initialVal = this.GetFromSession(this.Tipo_GasolinaSearch);
                
                if (initialVal != null && initialVal != "")		
                {
                        
                    this.Tipo_GasolinaSearch.Text = initialVal;
                            
                    }
            }
            // Control Initializations.
            // Initialize the table's current sort order.
          
            if (this.InSession(this, "Order_By")) {
                this.CurrentSortOrder = OrderBy.FromXmlString(this.GetFromSession(this, "Order_By", null));
            } else {
                this.CurrentSortOrder = new OrderBy(true, false);
            
            }

            // Setup default pagination settings.
    
            this.PageSize = Convert.ToInt32(this.GetFromSession(this, "Page_Size", "10"));
            this.PageIndex = Convert.ToInt32(this.GetFromSession(this, "Page_Index", "0"));
            
                    
            this.ClearControlsFromSession();
        }

        protected virtual void Control_Load(object sender, EventArgs e)
        {
        
            SaveControlsToSession_Ajax();
        
              // Show confirmation message on Click
              this.Tipo_GasolinaDeleteButton.Attributes.Add("onClick", "return (confirm('" + ((BaseApplicationPage)this.Page).GetResourceValue("DeleteConfirm", "EnGasAdoAPP") + "'));");
          // Setup the pagination events.
          
              this.Tipo_GasolinaPagination.FirstPage.Click += new ImageClickEventHandler(Tipo_GasolinaPagination_FirstPage_Click);
        
              this.Tipo_GasolinaPagination.LastPage.Click += new ImageClickEventHandler(Tipo_GasolinaPagination_LastPage_Click);
        
              this.Tipo_GasolinaPagination.NextPage.Click += new ImageClickEventHandler(Tipo_GasolinaPagination_NextPage_Click);
        
              this.Tipo_GasolinaPagination.PageSizeButton.Click += Tipo_GasolinaPagination_PageSizeButton_Click;
            
              this.Tipo_GasolinaPagination.PreviousPage.Click += new ImageClickEventHandler(Tipo_GasolinaPagination_PreviousPage_Click);
               
        
          // Setup the sorting events.
          
              this.descripcionLabel.Click += descripcionLabel_Click;
            
              this.Nombre_Tipo_GasolinaLabel.Click += Nombre_Tipo_GasolinaLabel_Click;
            
          // Setup the button events.
          
              this.Tipo_GasolinaAddButton.Click += new ImageClickEventHandler(Tipo_GasolinaAddButton_Click);
        
              this.Tipo_GasolinaDeleteButton.Click += new ImageClickEventHandler(Tipo_GasolinaDeleteButton_Click);
        
              this.Tipo_GasolinaSaveButton.Click += new ImageClickEventHandler(Tipo_GasolinaSaveButton_Click);
        
              this.Tipo_GasolinaSaveButton.Attributes.Add("onclick", "SubmitHRefOnce(this, \"" + this.Page.GetResourceValue("Txt:SaveRecord", "EnGasAdoAPP") + "\");");
        
              this.Tipo_GasolinaSearchButton.Button.Click += Tipo_GasolinaSearchButton_Click;
                    
          
          // Setup events for others
            
        }

        public virtual void LoadData()
        {
          
            // Read data from database. Returns an array of records that can be assigned
            // to the DataSource table control property.
            try {
              
                  CompoundFilter joinFilter = CreateCompoundJoinFilter();
                
                  // The WHERE clause will be empty when displaying all records in table.
                  WhereClause wc = CreateWhereClause();
                  if (wc != null && !wc.RunQuery) {
                    // Initialize an empty array of records
                    ArrayList alist = new ArrayList(0);
                  Type myrec = typeof(EnGasAdoAPP.Business.Tipo_GasolinaRecord);
                  this.DataSource = (Tipo_GasolinaRecord[])(alist.ToArray(myrec));
                  // Add records to the list if needed.
                  this.AddNewRecords();
                  return;
                  }

                  // Call OrderBy to determine the order - either use the order defined
                  // on the Query Wizard, or specified by user (by clicking on column heading)

                  OrderBy orderBy = CreateOrderBy();
              
      
                // Get the pagesize from the pagesize control.
                this.GetPageSize();

                // Get the total number of records to be displayed.
              
                this.TotalRecords = Tipo_GasolinaTable.GetRecordCount(joinFilter, wc);
              

                // Make sure PageIndex (current page) is within bounds.
                if (this.TotalPages <= 0 || this.PageIndex < 0) {
                    this.PageIndex = 0;
                }
                else if (this.DisplayLastPage || this.PageIndex >= this.TotalPages) {
                    this.PageIndex = this.TotalPages - 1;
                }

                // Retrieve the records and set the table DataSource.
                // Only PageSize records are fetched starting at PageIndex (zero based).
                if (this.TotalRecords <= 0) {
                    // No records matching query. Initialize an empty array of records
              
                    ArrayList alist = new ArrayList(0);
                    Type myrec = typeof(EnGasAdoAPP.Business.Tipo_GasolinaRecord);
                    this.DataSource = (Tipo_GasolinaRecord[])(alist.ToArray(myrec));
              
                }
                else if (this.AddNewRecord > 0) {
              
                    // Make sure to preserve the previously entered data on new rows.
                    ArrayList postdata = new ArrayList(0);
                    foreach (Tipo_GasolinaTableControlRow rc in this.GetRecordControls()) {
                        if (!rc.IsNewRecord) {
                            rc.DataSource = rc.GetRecord();
                            rc.GetUIData();
                            postdata.Add(rc.DataSource);
                            UIData.Add(rc.PreservedUIData());
                        }
                    }
                    Type myrec = typeof(EnGasAdoAPP.Business.Tipo_GasolinaRecord);
                    this.DataSource = (Tipo_GasolinaRecord[])(postdata.ToArray(myrec));
              
                } 
                else {
                    // Get the records from the database
                  
                    int totalRecords = this.TotalRecords;
                    this.DataSource = Tipo_GasolinaTable.GetRecords(joinFilter, wc, orderBy, this.PageIndex, this.PageSize, ref totalRecords);
                  
                }
                // Add any new rows desired by the user.
                this.AddNewRecords();
            
                // Turn off the ToggleAll checkbox
                this.Tipo_GasolinaToggleAll.Checked = false;
            

                // Initialize the page and grand totals. now
            

            // Add attributes to the export csv and excel button
            
    
            } catch (Exception ex) {
                // Report the error message to the end user
                    String msg = ex.Message;
                    if (ex.InnerException != null)
                        msg += " InnerException: " + ex.InnerException.Message;

                    throw new Exception(msg, ex.InnerException);
            }
        }
    
        
      public override void DataBind()
      {
          // The DataBind method binds the user interface controls to the values
          // from the database record for each row in the table.  To do this, it calls the
          // DataBind for each of the rows.
          // DataBind also populates any filters above the table, and sets the pagination
          // control to the correct number of records and the current page number.

          base.DataBind();

          // Make sure that the DataSource is initialized.
          if (this.DataSource == null) {
              return;
          }
          
          //  LoadData for DataSource for chart and report if they exist
               

            // Setup the pagination controls.
            BindPaginationControls();


        




    // Bind the repeater with the list of records to expand the UI.
    System.Web.UI.WebControls.Repeater rep = (System.Web.UI.WebControls.Repeater)(BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Tipo_GasolinaTableControlRepeater"));
    if (rep == null){return;}
    rep.DataSource = this.DataSource;
    rep.DataBind();

    int index = 0;
    foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items)
    {
    // Loop through all rows in the table, set its DataSource and call DataBind().
    Tipo_GasolinaTableControlRow recControl = (Tipo_GasolinaTableControlRow)(repItem.FindControl("Tipo_GasolinaTableControlRow"));
                recControl.DataSource = this.DataSource[index];
                if (this.UIData.Count > index) 
                    recControl.PreviousUIData = this.UIData[index];
                recControl.DataBind();
                recControl.Visible = !this.InDeletedRecordIds(recControl);
                index++;
            }
            
            // Call the Set methods for each controls on the panel
        
                SetdescripcionFilter();
                SetdescripcionLabel();
                SetdescripcionLabel1();
                SetNombre_Tipo_GasolinaFilter();
                SetNombre_Tipo_GasolinaLabel();
                SetNombre_Tipo_GasolinaLabel1();
                
                
                
                
                SetTipo_GasolinaSearch();
                
                
                
            // setting the state of expand or collapse alternative rows
      
            // Load data for each record and table UI control.
            // Ordering is important because child controls get 
            // their parent ids from their parent UI controls.
                
      
            // this method calls the set method for controls with special formula like running total, sum, rank, etc
            SetFormulaControls();
        }
        
        
        public virtual void SetFormulaControls()
        {
            // this method calls Set methods for the control that has special formula
        

    }

        

        public virtual void RegisterPostback()
        {
        
                  this.Page.RegisterPostBackTrigger(MiscUtils.FindControlRecursively(this,"Tipo_GasolinaSaveButton"));
                                
        }
        

        
          public BaseClasses.Data.DataSource.EvaluateFormulaDelegate EvaluateFormulaDelegate;

          public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, string format, System.Collections.Generic.IDictionary<string, object> variables, bool includeDS, FormulaEvaluator e)
          {
            if (e == null)
                e = new FormulaEvaluator();

            e.Variables.Clear();

            // add variables for formula evaluation
            if (variables != null)
            {
                System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<string, object>> enumerator = variables.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    e.Variables.Add(enumerator.Current.Key, enumerator.Current.Value);
                }
            }
            if (includeDS)
            {
                
            }

            // All variables referred to in the formula are expected to be
            // properties of the DataSource.  For example, referring to
            // UnitPrice as a variable will refer to DataSource.UnitPrice
            e.DataSource = dataSourceForEvaluate;

            // Define the calling control.  This is used to add other 
            // related table and record controls as variables.
            e.CallingControl = this;

            object resultObj = e.Evaluate(formula);
            if (resultObj == null)
                return "";
            
            if ( !string.IsNullOrEmpty(format) && (string.IsNullOrEmpty(formula) || formula.IndexOf("Format(") < 0) )
                return FormulaUtils.Format(resultObj, format);
            else
                return resultObj.ToString();
        }
        
        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, string format, System.Collections.Generic.IDictionary<string, object> variables, bool includeDS)
        {
          return EvaluateFormula(formula, dataSourceForEvaluate, format, variables, includeDS, null);
        }

        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, string format, System.Collections.Generic.IDictionary<string, object> variables)
        {
          return EvaluateFormula(formula, dataSourceForEvaluate, format, variables, true, null);
        }

        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, string format)
        {
          return this.EvaluateFormula(formula, dataSourceForEvaluate, format, null, true, null);
        }

        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, System.Collections.Generic.IDictionary<string, object> variables, FormulaEvaluator e)
        {
          return this.EvaluateFormula(formula, dataSourceForEvaluate, null, variables, true, e);
        }

        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate)
        {
          return this.EvaluateFormula(formula, dataSourceForEvaluate, null, null, true, null);
        }

        public virtual string EvaluateFormula(string formula, bool includeDS)
        {
          return this.EvaluateFormula(formula, null, null, null, includeDS, null);
        }

        public virtual string EvaluateFormula(string formula)
        {
          return this.EvaluateFormula(formula, null, null, null, true, null);
        }
           
        public virtual void ResetControl()
        {
            
            this.descripcionFilter.ClearSelection();
            
            this.Nombre_Tipo_GasolinaFilter.ClearSelection();
            
            this.Tipo_GasolinaSearch.Text = "";
            
            this.CurrentSortOrder.Reset();
            if (this.InSession(this, "Order_By")) {
                this.CurrentSortOrder = OrderBy.FromXmlString(this.GetFromSession(this, "Order_By", null));
            }
            else {
                this.CurrentSortOrder = new OrderBy(true, false);
               
            }
                
            this.PageIndex = 0;
        }
        
        
        protected virtual void BindPaginationControls()
        {
            // Setup the pagination controls.

            // Bind the buttons for Tipo_GasolinaTableControl pagination.
        
            this.Tipo_GasolinaPagination.FirstPage.Enabled = !(this.PageIndex == 0);
            this.Tipo_GasolinaPagination.LastPage.Enabled = !(this.PageIndex == this.TotalPages - 1);
            if (this.TotalPages == 0) {
                this.Tipo_GasolinaPagination.LastPage.Enabled = false;
            }
          
            this.Tipo_GasolinaPagination.NextPage.Enabled = !(this.PageIndex == this.TotalPages - 1);
            if (this.TotalPages == 0) {
                this.Tipo_GasolinaPagination.NextPage.Enabled = false;
            }
          
            this.Tipo_GasolinaPagination.PreviousPage.Enabled = !(this.PageIndex == 0);

            // Bind the pagination labels.
        
            if (this.TotalPages > 0) {
                this.Tipo_GasolinaPagination.CurrentPage.Text = (this.PageIndex + 1).ToString();
            } else {
                this.Tipo_GasolinaPagination.CurrentPage.Text = "0";
            }
            this.Tipo_GasolinaPagination.PageSize.Text = this.PageSize.ToString();
            this.Tipo_GasolinaPagination.TotalPages.Text = this.TotalPages.ToString();
        }

        public virtual void SaveData()
        {
            // Save the data from the entire table.  Calls each row's Save Data
            // to save their data.  This function is called by the Click handler of the
            // Save button.  The button handler should Start/Commit/End a transaction.
            
            foreach (Tipo_GasolinaTableControlRow recCtl in this.GetRecordControls())
            {
        
                if (this.InDeletedRecordIds(recCtl)) {
                    // Delete any pending deletes. 
                    recCtl.Delete();
                }
                else {
                    if (recCtl.Visible) {
                        recCtl.SaveData();
                    }
                }
          
            }

            // Setting the DataChanged to True results in the page being refreshed with
            // the most recent data from the database.  This happens in PreRender event
            // based on the current sort, search and filter criteria.
            this.DataChanged = true;
            this.ResetData = true;
          
            // Set IsNewRecord to False for all records - since everything has been saved and is no longer "new"
            foreach (Tipo_GasolinaTableControlRow recCtl in this.GetRecordControls()){
                recCtl.IsNewRecord = false;
            }
      
            // Set DeletedRecordsIds to Nothing since we have deleted all pending deletes.
            this.DeletedRecordIds = null;
      
        }
        
        public virtual CompoundFilter CreateCompoundJoinFilter()
        {
            CompoundFilter jFilter = new CompoundFilter();
        
            return jFilter;
        }      
        
    
        public virtual OrderBy CreateOrderBy()
        {
            // The CurrentSortOrder is initialized to the sort order on the 
            // Query Wizard.  It may be modified by the Click handler for any of
            // the column heading to sort or reverse sort by that column.
            // You can add your own sort order, or modify it on the Query Wizard.
            return this.CurrentSortOrder;
        }
         
        
        private string parentSelectedKeyValue;
        public string ParentSelectedKeyValue
        {
          get
          {
            return parentSelectedKeyValue;
          }
          set
          {
            parentSelectedKeyValue = value;
          }
        }

    
        public virtual WhereClause CreateWhereClause()
        {
            // This CreateWhereClause is used for loading the data.
            Tipo_GasolinaTable.Instance.InnerFilter = null;
            WhereClause wc = new WhereClause();
         
            // CreateWhereClause() Compose the WHERE clause consiting of:
            // 1. Static clause defined at design time.
            // 2. User selected search criteria.
            // 3. User selected filter criteria.
            
        
            if (MiscUtils.IsValueSelected(this.descripcionFilter)) {
                        
                wc.iAND(Tipo_GasolinaTable.descripcion, BaseFilter.ComparisonOperator.EqualsTo, MiscUtils.GetSelectedValue(this.descripcionFilter, this.GetFromSession(this.descripcionFilter)), false, false);
            
            }
                      
            if (MiscUtils.IsValueSelected(this.Nombre_Tipo_GasolinaFilter)) {
                        
                wc.iAND(Tipo_GasolinaTable.Nombre_Tipo_Gasolina, BaseFilter.ComparisonOperator.EqualsTo, MiscUtils.GetSelectedValue(this.Nombre_Tipo_GasolinaFilter, this.GetFromSession(this.Nombre_Tipo_GasolinaFilter)), false, false);
            
            }
                      
            if (MiscUtils.IsValueSelected(this.Tipo_GasolinaSearch)) {
                // Strip "..." from begin and ending of the search text, otherwise the search will return 0 values as in database "..." is not stored.
                if (this.Tipo_GasolinaSearch.Text.StartsWith("...")) {
                    this.Tipo_GasolinaSearch.Text = this.Tipo_GasolinaSearch.Text.Substring(3,this.Tipo_GasolinaSearch.Text.Length-3);
                }
                if (this.Tipo_GasolinaSearch.Text.EndsWith("...")) {
                    this.Tipo_GasolinaSearch.Text = this.Tipo_GasolinaSearch.Text.Substring(0,this.Tipo_GasolinaSearch.Text.Length-3);
                    // Strip the last word as well as it is likely only a partial word
                    int endindex = this.Tipo_GasolinaSearch.Text.Length - 1;
                    while (!Char.IsWhiteSpace(Tipo_GasolinaSearch.Text[endindex]) && endindex > 0) {
                        endindex--;
                    }
                    if (endindex > 0) {
                        this.Tipo_GasolinaSearch.Text = this.Tipo_GasolinaSearch.Text.Substring(0, endindex);
                    }
                }
                string formatedSearchText = MiscUtils.GetSelectedValue(this.Tipo_GasolinaSearch, this.GetFromSession(this.Tipo_GasolinaSearch));
                // After stripping "..." see if the search text is null or empty.
                if (MiscUtils.IsValueSelected(this.Tipo_GasolinaSearch)) {
                      
                    // These clauses are added depending on operator and fields selected in Control's property page, bindings tab.
                  
                    WhereClause search = new WhereClause();
                    
                    search.iOR(Tipo_GasolinaTable.Nombre_Tipo_Gasolina, BaseFilter.ComparisonOperator.Contains, formatedSearchText, true, false);
        
                    search.iOR(Tipo_GasolinaTable.descripcion, BaseFilter.ComparisonOperator.Contains, formatedSearchText, true, false);
        
                    wc.iAND(search);
                  
                }
            }
                  
            return wc;
        }
        
         
        public virtual WhereClause CreateWhereClause(String searchText, String fromSearchControl, String AutoTypeAheadSearch, String AutoTypeAheadWordSeparators)
        {
            // This CreateWhereClause is used for loading list of suggestions for Auto Type-Ahead feature.
            Tipo_GasolinaTable.Instance.InnerFilter = null;
            WhereClause wc = new WhereClause();
        
            // Compose the WHERE clause consiting of:
            // 1. Static clause defined at design time.
            // 2. User selected search criteria.
            // 3. User selected filter criteria.
            
            String appRelativeVirtualPath = (String)HttpContext.Current.Session["AppRelativeVirtualPath"];
            
            // Adds clauses if values are selected in Filter controls which are configured in the page.
          
      String descripcionFilterSelectedValue = (String)HttpContext.Current.Session[HttpContext.Current.Session.SessionID + appRelativeVirtualPath + "descripcionFilter_Ajax"];
            if (MiscUtils.IsValueSelected(descripcionFilterSelectedValue)) {
              
                wc.iAND(Tipo_GasolinaTable.descripcion, BaseFilter.ComparisonOperator.EqualsTo, descripcionFilterSelectedValue, false, false);
                    
      }
                      
      String Nombre_Tipo_GasolinaFilterSelectedValue = (String)HttpContext.Current.Session[HttpContext.Current.Session.SessionID + appRelativeVirtualPath + "Nombre_Tipo_GasolinaFilter_Ajax"];
            if (MiscUtils.IsValueSelected(Nombre_Tipo_GasolinaFilterSelectedValue)) {
              
                wc.iAND(Tipo_GasolinaTable.Nombre_Tipo_Gasolina, BaseFilter.ComparisonOperator.EqualsTo, Nombre_Tipo_GasolinaFilterSelectedValue, false, false);
                    
      }
                      
            if (MiscUtils.IsValueSelected(searchText) && fromSearchControl == "Tipo_GasolinaSearch") {
                String formatedSearchText = searchText;
                // strip "..." from begin and ending of the search text, otherwise the search will return 0 values as in database "..." is not stored.
                
                  if (searchText.StartsWith("...")) {
                      formatedSearchText = searchText.Substring(3,searchText.Length-3);
                  }
                  if (searchText.EndsWith("...")) {
                      formatedSearchText = searchText.Substring(0,searchText.Length-3);
                  }
                
                // After stripping "...", trim any leading and trailing whitespaces 
                formatedSearchText = formatedSearchText.Trim();
                // After stripping "..." see if the search text is null or empty.
                if (MiscUtils.IsValueSelected(searchText)) {
                      
                    // These clauses are added depending on operator and fields selected in Control's property page, bindings tab.
                  
                    WhereClause search = new WhereClause();
                    
                    if (StringUtils.InvariantLCase(AutoTypeAheadSearch).Equals("wordsstartingwithsearchstring")) {
                
                        search.iOR(Tipo_GasolinaTable.Nombre_Tipo_Gasolina, BaseFilter.ComparisonOperator.Starts_With, formatedSearchText, true, false);
                        search.iOR(Tipo_GasolinaTable.Nombre_Tipo_Gasolina, BaseFilter.ComparisonOperator.Contains, AutoTypeAheadWordSeparators + formatedSearchText, true, false);
                  
                
                        search.iOR(Tipo_GasolinaTable.descripcion, BaseFilter.ComparisonOperator.Starts_With, formatedSearchText, true, false);
                        search.iOR(Tipo_GasolinaTable.descripcion, BaseFilter.ComparisonOperator.Contains, AutoTypeAheadWordSeparators + formatedSearchText, true, false);
                  
                
                    } else {
                        
                        search.iOR(Tipo_GasolinaTable.Nombre_Tipo_Gasolina, BaseFilter.ComparisonOperator.Contains, formatedSearchText, true, false);
                        search.iOR(Tipo_GasolinaTable.descripcion, BaseFilter.ComparisonOperator.Contains, formatedSearchText, true, false);
                    } 
                    wc.iAND(search);
                  
                }
            }
                  
            return wc;
        }
          
        public virtual string[] GetAutoCompletionList_Tipo_GasolinaSearch(String prefixText,int count)
        {
            ArrayList resultList = new ArrayList();
            ArrayList wordList= new ArrayList();
            int iteration = 0;
            
            WhereClause wc = CreateWhereClause(prefixText,"Tipo_GasolinaSearch", "WordsStartingWithSearchString", "[^a-zA-Z0-9]");
            while (resultList.Count < count && iteration < 5){
                // Fetch 100 records in each iteration
                EnGasAdoAPP.Business.Tipo_GasolinaRecord[] recordList  = Tipo_GasolinaTable.GetRecords(wc, null, iteration, 100);
                String resultItem = "";
                foreach (Tipo_GasolinaRecord rec in recordList ){
                    // Exit the loop if recordList count has reached AutoTypeAheadListSize.
                    if (resultList.Count >= count) {
                        break;
                    }
                    // If the field is configured to Display as Foreign key, Format() method returns the 
                    // Display as Forien Key value instead of original field value.
                    // Since search had to be done in multiple fields (selected in Control's page property, binding tab) in a record,
                    // We need to find relevent field to display which matches the prefixText and is not already present in the result list.
            
                    resultItem = rec.Format(Tipo_GasolinaTable.Nombre_Tipo_Gasolina);
      
                    if (resultItem != null && resultItem.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture).Contains(prefixText.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture))) {
                        bool isAdded = FormatSuggestions(prefixText, resultItem, 50, "AtBeginningOfMatchedString", "WordsStartingWithSearchString", "[^a-zA-Z0-9]", resultList);
                        if (isAdded) {
                            continue;
                        }
                    }
      
                    resultItem = rec.Format(Tipo_GasolinaTable.descripcion);
      
                    if (resultItem != null && resultItem.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture).Contains(prefixText.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture))) {
                        bool isAdded = FormatSuggestions(prefixText, resultItem, 50, "AtBeginningOfMatchedString", "WordsStartingWithSearchString", "[^a-zA-Z0-9]", resultList);
                        if (isAdded) {
                            continue;
                        }
                    }
      
                }
                // Exit the loop if number of records found is less as further iteration will not return any more records
                if (recordList .Length < 100 ) {
                    break;
                }
                iteration++;
            }
              
            resultList.Sort();
            string[] result = new string[resultList.Count];
            Array.Copy(resultList.ToArray(), result, resultList.Count);
            return result;
        }
          
        public virtual bool FormatSuggestions(String prefixText, String resultItem,
                                              int columnLength, String AutoTypeAheadDisplayFoundText,
                                              String autoTypeAheadSearch, String AutoTypeAheadWordSeparators,
                                              ArrayList resultList)
        {
            // Formats the result Item and adds it to the list of suggestions.
            int index  = resultItem.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture).IndexOf(prefixText.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture));
            String itemToAdd = null;
            bool isFound = false;
            bool isAdded = false;
            if (StringUtils.InvariantLCase(autoTypeAheadSearch).Equals("wordsstartingwithsearchstring") && !(index == 0)) {
                 // Expression to find word which contains AutoTypeAheadWordSeparators followed by prefixText
                System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex( AutoTypeAheadWordSeparators + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                if (regex1.IsMatch(resultItem)) {
                    index = regex1.Match(resultItem).Index;
                    isFound = true;
                }
                //If the prefixText is found immediatly after white space then starting of the word is found so don not search any further
                if (resultItem[index].ToString() != " ") {
                    // Expression to find beginning of the word which contains AutoTypeAheadWordSeparators followed by prefixText
                    System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("\\S*" + AutoTypeAheadWordSeparators + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    if (regex.IsMatch(resultItem)) {
                        index = regex.Match(resultItem).Index;
                        isFound = true;
                    }
                }
            }
            // If autoTypeAheadSearch value is wordsstartingwithsearchstring then, extract the substring only if the prefixText is found at the 
            // beginning of the resultItem (index = 0) or a word in resultItem is found starts with prefixText. 
            if (index == 0 || isFound || StringUtils.InvariantLCase(autoTypeAheadSearch).Equals("anywhereinstring")) {
                if (StringUtils.InvariantLCase(AutoTypeAheadDisplayFoundText).Equals("atbeginningofmatchedstring")) {
                    // Expression to find beginning of the word which contains prefixText
                    System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex("\\S*" + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    //  Find the beginning of the word which contains prefexText
                    if (StringUtils.InvariantLCase(autoTypeAheadSearch).Equals("anywhereinstring") && regex1.IsMatch(resultItem)) {
                        index = regex1.Match(resultItem).Index;
                        isFound = true;
                    }
                    // Display string from the index till end of the string if, sub string from index till end of string is less than columnLength value.
                    if ((resultItem.Length - index) <= columnLength) {
                        if (index == 0) {
                            itemToAdd = resultItem;
                        } else {
                            itemToAdd = "..." + resultItem.Substring(index, resultItem.Length - index);
                        }
                    } else {
                        if (index == 0) {
                          itemToAdd = resultItem.Substring(index, (columnLength - 3)) + "...";
                        } else {
                            // Truncate the string to show only columnLength - 6 characters as begining and trailing "..." has to be appended.
                            itemToAdd = "..." + resultItem.Substring(index, (columnLength - 6)) + "...";
                        }
                    }
                } else if (StringUtils.InvariantLCase(AutoTypeAheadDisplayFoundText).Equals("inmiddleofmatchedstring")) {
                    int subStringBeginIndex = (int)(columnLength / 2);
                    if (resultItem.Length <= columnLength) {
                        itemToAdd = resultItem;
                    } else {
                        // Sanity check at end of the string
                        if ((index + prefixText.Length) == columnLength) {
                            itemToAdd = "..." + resultItem.Substring((index - columnLength), index);
                        } else if ((resultItem.Length - index) < subStringBeginIndex) {
                            //  Display string from the end till columnLength value if, index is closer to the end of the string.
                            itemToAdd = "..." + resultItem.Substring(resultItem.Length - columnLength, resultItem.Length);
                        } else if (index <= subStringBeginIndex) {
                            // Sanity chet at beginning of the string
                            itemToAdd = resultItem.Substring(0, columnLength) + "...";
                        } else {
                            // Display string containing text before the prefixText occures and text after the prefixText
                            itemToAdd = "..." + resultItem.Substring(index - subStringBeginIndex, columnLength) + "...";
                        }
                    }
                } else if (StringUtils.InvariantLCase(AutoTypeAheadDisplayFoundText).Equals("atendofmatchedstring")) {
                     // Expression to find ending of the word which contains prefexText
                    System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex("\\s", System.Text.RegularExpressions.RegexOptions.IgnoreCase); 
                    // Find the ending of the word which contains prefexText
                    if (regex1.IsMatch(resultItem, index + 1)) {
                        index = regex1.Match(resultItem, index + 1).Index;
                    }else{
                        // If the word which contains prefexText is the last word in string, regex1.IsMatch returns false.
                        index = resultItem.Length;
                    }
                    
                    if (index > resultItem.Length) {
                        index = resultItem.Length;
                    }
                    // If text from beginning of the string till index is less than columnLength value then, display string from the beginning till index.
                    if (index <= columnLength) {
                        if (index == resultItem.Length) {   //Make decision to append "..."
                            itemToAdd = resultItem.Substring(0, index);
                        } else {
                            itemToAdd = resultItem.Substring(0, index) + "...";
                        }
                    } else if (index == resultItem.Length) {
                        itemToAdd = "..." + resultItem.Substring(index - (columnLength - 3), columnLength - 3);
                    } else {
                        // Truncate the string to show only columnLength - 6 characters as begining and trailing "..." has to be appended.
                        itemToAdd = "..." + resultItem.Substring(index - (columnLength - 6), (columnLength - 6)) + "...";
                    }
                }
                
                // Remove newline character from itemToAdd
                int prefixTextIndex = itemToAdd.IndexOf(prefixText, StringComparison.CurrentCultureIgnoreCase);
                // If itemToAdd contains any newline after the search text then show text only till newline
                System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex("(\r\n|\n)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                int newLineIndexAfterPrefix = -1;
                if (regex2.IsMatch(itemToAdd, prefixTextIndex)){
                    newLineIndexAfterPrefix = regex2.Match(itemToAdd, prefixTextIndex).Index;
                }
                if ((newLineIndexAfterPrefix > -1)) {
                    if (itemToAdd.EndsWith("...")) {
                        itemToAdd = itemToAdd.Substring(0, newLineIndexAfterPrefix) + "...";
                    }
                    else {
                        itemToAdd = itemToAdd.Substring(0, newLineIndexAfterPrefix);
                    }
                }
                // If itemToAdd contains any newline before search text then show text which comes after newline
                System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex("(\r\n|\n)", System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.RightToLeft );
                int newLineIndexBeforePrefix = -1;
                if (regex3.IsMatch(itemToAdd, prefixTextIndex)){
                    newLineIndexBeforePrefix = regex3.Match(itemToAdd, prefixTextIndex).Index;
                }
                if ((newLineIndexBeforePrefix > -1)) {
                    if (itemToAdd.StartsWith("...")) {
                        itemToAdd = "..." + itemToAdd.Substring(newLineIndexBeforePrefix +regex3.Match(itemToAdd, prefixTextIndex).Length);
                    }
                    else {
                        itemToAdd = itemToAdd.Substring(newLineIndexBeforePrefix +regex3.Match(itemToAdd, prefixTextIndex).Length);
                    }
                }

                if (itemToAdd!= null && !resultList.Contains(itemToAdd)) {
                    
                    resultList.Add(itemToAdd);
          								
                    isAdded = true;
                }
            }
            return isAdded;
        }
        
        
    
        protected virtual void GetPageSize()
        {
        
            if (this.Tipo_GasolinaPagination.PageSize.Text.Length > 0) {
                try {
                    // this.PageSize = Convert.ToInt32(this.Tipo_GasolinaPagination.PageSize.Text);
                } catch (Exception ) {
                }
            }
        }

        protected virtual void AddNewRecords()
        {
          
            ArrayList newRecordList = new ArrayList();
          
            System.Collections.Generic.List<Hashtable> newUIDataList = new System.Collections.Generic.List<Hashtable>();
    // Loop though all the record controls and if the record control
    // does not have a unique record id set, then create a record
    // and add to the list.
    if (!this.ResetData)
    {
    System.Web.UI.WebControls.Repeater rep = (System.Web.UI.WebControls.Repeater)(BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Tipo_GasolinaTableControlRepeater"));
    if (rep == null){return;}

    foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items)
    {
    // Loop through all rows in the table, set its DataSource and call DataBind().
    Tipo_GasolinaTableControlRow recControl = (Tipo_GasolinaTableControlRow)(repItem.FindControl("Tipo_GasolinaTableControlRow"));

                    if (recControl.Visible && recControl.IsNewRecord) {
                      Tipo_GasolinaRecord rec = new Tipo_GasolinaRecord();
        
                        if (recControl.descripcion.Text != "") {
                            rec.Parse(recControl.descripcion.Text, Tipo_GasolinaTable.descripcion);
                  }
                
                        if (recControl.Nombre_Tipo_Gasolina.Text != "") {
                            rec.Parse(recControl.Nombre_Tipo_Gasolina.Text, Tipo_GasolinaTable.Nombre_Tipo_Gasolina);
                  }
                
                        newUIDataList.Add(recControl.PreservedUIData());
                        newRecordList.Add(rec);
                    }
                }
            }

            // Add any new record to the list.
            for (int count = 1; count <= this.AddNewRecord; count++) {
              
                newRecordList.Insert(0, new Tipo_GasolinaRecord());
                newUIDataList.Insert(0, new Hashtable());
              
            }
            this.AddNewRecord = 0;

            // Finally, add any new records to the DataSource.
            if (newRecordList.Count > 0) {
              
                ArrayList finalList = new ArrayList(this.DataSource);
                finalList.InsertRange(0, newRecordList);

                Type myrec = typeof(EnGasAdoAPP.Business.Tipo_GasolinaRecord);
                this.DataSource = (Tipo_GasolinaRecord[])(finalList.ToArray(myrec));
              
            }
            
            // Add the existing UI data to this hash table
            if (newUIDataList.Count > 0)
                this.UIData.InsertRange(0, newUIDataList);
        }

        
        public void AddToDeletedRecordIds(Tipo_GasolinaTableControlRow rec)
        {
            if (rec.IsNewRecord) {
                return;
            }

            if (this.DeletedRecordIds != null && this.DeletedRecordIds.Length > 0) {
                this.DeletedRecordIds += ",";
            }

            this.DeletedRecordIds += "[" + rec.RecordUniqueId + "]";
        }

        protected virtual bool InDeletedRecordIds(Tipo_GasolinaTableControlRow rec)            
        {
            if (this.DeletedRecordIds == null || this.DeletedRecordIds.Length == 0) {
                return (false);
            }

            return (this.DeletedRecordIds.IndexOf("[" + rec.RecordUniqueId + "]") >= 0);
        }

        private String _DeletedRecordIds;
        public String DeletedRecordIds {
            get {
                return (this._DeletedRecordIds);
            }
            set {
                this._DeletedRecordIds = value;
            }
        }
        
      
        // Create Set, WhereClause, and Populate Methods
        
        public virtual void SetdescripcionLabel()
                  {
                  
                    
        }
                
        public virtual void SetdescripcionLabel1()
                  {
                  
                    
        }
                
        public virtual void SetNombre_Tipo_GasolinaLabel()
                  {
                  
                    
        }
                
        public virtual void SetNombre_Tipo_GasolinaLabel1()
                  {
                  
                    
        }
                
        public virtual void SetdescripcionFilter()
        {
            
                this.PopulatedescripcionFilter(MiscUtils.GetSelectedValue(this.descripcionFilter,  GetFromSession(this.descripcionFilter)), 500);					
                    
        }
            
        public virtual void SetNombre_Tipo_GasolinaFilter()
        {
            
                this.PopulateNombre_Tipo_GasolinaFilter(MiscUtils.GetSelectedValue(this.Nombre_Tipo_GasolinaFilter,  GetFromSession(this.Nombre_Tipo_GasolinaFilter)), 500);					
                    
        }
            
        public virtual void SetTipo_GasolinaSearch()
        {
            
        }
            
        // Get the filters' data for descripcionFilter.
                
        protected virtual void PopulatedescripcionFilter(string selectedValue, int maxItems)
                    
        {
            this.descripcionFilter.Items.Clear();
                        
            		  			
            // Set up the WHERE and the ORDER BY clause by calling the CreateWhereClause_descripcionFilter function.
            // It is better to customize the where clause there.
          
            // Setup the WHERE clause, 
                
            WhereClause wc = this.CreateWhereClause_descripcionFilter();

            // Setup the static list items        
            
            // Add the All item.
            this.descripcionFilter.Items.Insert(0, new ListItem(this.Page.GetResourceValue("Txt:All", "EnGasAdoAPP"), "--ANY--"));
                            

            OrderBy orderBy = new OrderBy(false, false);
            orderBy.Add(Tipo_GasolinaTable.descripcion, OrderByItem.OrderDir.Asc);                

            
            string[] values = Tipo_GasolinaTable.GetValues(Tipo_GasolinaTable.descripcion, wc, orderBy, maxItems);              
            
            foreach (string itemValue in values)
            {
            // Create the item and add to the list.
            string fvalue;
            if ( Tipo_GasolinaTable.descripcion.IsColumnValueTypeBoolean()) {
                    fvalue = itemValue;
                }else {
                    fvalue = Tipo_GasolinaTable.descripcion.Format(itemValue);
                }
                ListItem item = new ListItem(fvalue, itemValue);
                this.descripcionFilter.Items.Add(item);
            }
          
      
            // Set the selected value.
            MiscUtils.SetSelectedValue(this.descripcionFilter, selectedValue);

            
        }
            
        // Get the filters' data for Nombre_Tipo_GasolinaFilter.
                
        protected virtual void PopulateNombre_Tipo_GasolinaFilter(string selectedValue, int maxItems)
                    
        {
            this.Nombre_Tipo_GasolinaFilter.Items.Clear();
                        
            		  			
            // Set up the WHERE and the ORDER BY clause by calling the CreateWhereClause_Nombre_Tipo_GasolinaFilter function.
            // It is better to customize the where clause there.
          
            // Setup the WHERE clause, 
                
            WhereClause wc = this.CreateWhereClause_Nombre_Tipo_GasolinaFilter();

            // Setup the static list items        
            
            // Add the All item.
            this.Nombre_Tipo_GasolinaFilter.Items.Insert(0, new ListItem(this.Page.GetResourceValue("Txt:All", "EnGasAdoAPP"), "--ANY--"));
                            

            OrderBy orderBy = new OrderBy(false, false);
            orderBy.Add(Tipo_GasolinaTable.Nombre_Tipo_Gasolina, OrderByItem.OrderDir.Asc);                

            
            string[] values = Tipo_GasolinaTable.GetValues(Tipo_GasolinaTable.Nombre_Tipo_Gasolina, wc, orderBy, maxItems);              
            
            foreach (string itemValue in values)
            {
            // Create the item and add to the list.
            string fvalue;
            if ( Tipo_GasolinaTable.Nombre_Tipo_Gasolina.IsColumnValueTypeBoolean()) {
                    fvalue = itemValue;
                }else {
                    fvalue = Tipo_GasolinaTable.Nombre_Tipo_Gasolina.Format(itemValue);
                }
                ListItem item = new ListItem(fvalue, itemValue);
                this.Nombre_Tipo_GasolinaFilter.Items.Add(item);
            }
          
      
            // Set the selected value.
            MiscUtils.SetSelectedValue(this.Nombre_Tipo_GasolinaFilter, selectedValue);

            
        }
            
        public virtual WhereClause CreateWhereClause_descripcionFilter()
        {
        
            // Create a where clause for the filter descripcionFilter.
            // This function is called by the Populate method to load the items 
            // in the descripcionFilterDropDownList
        
            WhereClause wc = new WhereClause();
            return wc;
            
        }
      
        public virtual WhereClause CreateWhereClause_Nombre_Tipo_GasolinaFilter()
        {
        
            // Create a where clause for the filter Nombre_Tipo_GasolinaFilter.
            // This function is called by the Populate method to load the items 
            // in the Nombre_Tipo_GasolinaFilterDropDownList
        
            WhereClause wc = new WhereClause();
            return wc;
            
        }
      

    
        protected virtual void Control_PreRender(object sender, System.EventArgs e)
        {
            // PreRender event is raised just before page is being displayed.
            try {
                DbUtils.StartTransaction();
                this.RegisterPostback();
                if (!this.Page.ErrorOnPage && (this.Page.IsPageRefresh || this.DataChanged || this.ResetData)) {
                  
                
                    // Re-load the data and update the web page if necessary.
                    // This is typically done during a postback (filter, search button, sort, pagination button).
                    // In each of the other click handlers, simply set DataChanged to True to reload the data.
                    bool added = (this.AddNewRecord > 0);
                    this.LoadData();
                    this.DataBind();					
                    
                    if (added) this.SetFocusToAddedRow();
                }
                                
            } catch (Exception ex) {
                BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
            } finally {
                DbUtils.EndTransaction();
            }
        }
        
            protected virtual void SetFocusToAddedRow()
            {
            System.Web.UI.WebControls.Repeater rep = (System.Web.UI.WebControls.Repeater)this.FindControl("Tipo_GasolinaTableControlRepeater");
            if (rep == null || rep.Items.Count == 0) return; 			
            foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items) {
                // Loop through all rows in the table, set its DataSource and call DataBind().
                //load scripts to the repeater
                this.Page.LoadFocusScripts(repItem);
                Tipo_GasolinaTableControlRow recControl = (Tipo_GasolinaTableControlRow)repItem.FindControl("Tipo_GasolinaTableControlRow");
                if(recControl.IsNewRecord) {
                    foreach (Control field in recControl.Controls) {
                    if (field.Visible && this.Page.IsControlEditable(field, false)) {
                        //set focus on the first editable field in the new row
                        field.Focus();
                        UpdatePanel updPan = (UpdatePanel)this.Page.FindControlRecursively("UpdatePanel1");
                        if (updPan != null) updPan.Update();
                        return;
                        }
                    }
                    return;
                }
            }
        }
        
        protected override void SaveControlsToSession()
        {
            base.SaveControlsToSession();
            // Save filter controls to values to session.
        
            this.SaveToSession(this.descripcionFilter, this.descripcionFilter.SelectedValue);
                  
            this.SaveToSession(this.Nombre_Tipo_GasolinaFilter, this.Nombre_Tipo_GasolinaFilter.SelectedValue);
                  
            this.SaveToSession(this.Tipo_GasolinaSearch, this.Tipo_GasolinaSearch.Text);
                  
            
                    
            // Save pagination state to session.
        
    
            // Save table control properties to the session.
          
            if (this.CurrentSortOrder != null) {
                this.SaveToSession(this, "Order_By", this.CurrentSortOrder.ToXmlString());
            }
          
            this.SaveToSession(this, "Page_Index", this.PageIndex.ToString());
            this.SaveToSession(this, "Page_Size", this.PageSize.ToString());
        
            this.SaveToSession(this, "DeletedRecordIds", this.DeletedRecordIds);
        
        }
        
        
        protected  void SaveControlsToSession_Ajax()
        {
            // Save filter controls to values to session.
          
      this.SaveToSession("descripcionFilter_Ajax", this.descripcionFilter.SelectedValue);
              
      this.SaveToSession("Nombre_Tipo_GasolinaFilter_Ajax", this.Nombre_Tipo_GasolinaFilter.SelectedValue);
              
      this.SaveToSession("Tipo_GasolinaSearch_Ajax", this.Tipo_GasolinaSearch.Text);
              
           HttpContext.Current.Session["AppRelativeVirtualPath"] = this.Page.AppRelativeVirtualPath;
         
        }
        
        
        protected override void ClearControlsFromSession()
        {
            base.ClearControlsFromSession();
            // Clear filter controls values from the session.
        
            this.RemoveFromSession(this.descripcionFilter);
            this.RemoveFromSession(this.Nombre_Tipo_GasolinaFilter);
            this.RemoveFromSession(this.Tipo_GasolinaSearch);
            
            // Clear pagination state from session.
        
    
            // Clear table properties from the session.
            this.RemoveFromSession(this, "Order_By");
            this.RemoveFromSession(this, "Page_Index");
            this.RemoveFromSession(this, "Page_Size");
            
            this.RemoveFromSession(this, "DeletedRecordIds");
            
        }

        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);

            string orderByStr = (string)ViewState["Tipo_GasolinaTableControl_OrderBy"];
          
            if (orderByStr != null && orderByStr.Length > 0) {
                this.CurrentSortOrder = BaseClasses.Data.OrderBy.FromXmlString(orderByStr);
            }
            else {
                this.CurrentSortOrder = new OrderBy(true, false);
            }
          

            if (ViewState["Page_Index"] != null) {
                this.PageIndex = (int)ViewState["Page_Index"];
            }

            if (ViewState["Page_Size"] != null) {
                this.PageSize = (int)ViewState["Page_Size"];
            }
            
            // Load view state for pagination control.
        
            this.DeletedRecordIds = (string)this.ViewState["DeletedRecordIds"];
        
        }

        protected override object SaveViewState()
        {            
          
            if (this.CurrentSortOrder != null) {
                this.ViewState["Tipo_GasolinaTableControl_OrderBy"] = this.CurrentSortOrder.ToXmlString();
            }
          
            
            this.ViewState["Page_Index"] = this.PageIndex;
            this.ViewState["Page_Size"] = this.PageSize;
        
            this.ViewState["DeletedRecordIds"] = this.DeletedRecordIds;
        
    
            // Load view state for pagination control.
              
            return (base.SaveViewState());
        }
        
        // Generate the event handling functions for pagination events.
        
        // Event handler for Tipo_GasolinaPaginationImageButton .
        public virtual void Tipo_GasolinaPagination_FirstPage_Click(object sender, ImageClickEventArgs args)
        {
        
            try {
                
            this.PageIndex = 0;
            this.DataChanged = true;
      
            } catch (Exception ex) {
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
    
            }
    
        }
        
        // Event handler for Tipo_GasolinaPaginationImageButton .
        public virtual void Tipo_GasolinaPagination_LastPage_Click(object sender, ImageClickEventArgs args)
        {
        
            try {
                
            this.DisplayLastPage = true;
            this.DataChanged = true;
      
            } catch (Exception ex) {
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
    
            }
    
        }
        
        // Event handler for Tipo_GasolinaPaginationImageButton .
        public virtual void Tipo_GasolinaPagination_NextPage_Click(object sender, ImageClickEventArgs args)
        {
        
            try {
                
            this.PageIndex += 1;
            this.DataChanged = true;
      
            } catch (Exception ex) {
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
    
            }
    
        }
        
        // event handler for Tipo_GasolinaPaginationPageSizeButtonLinkButton  
        public virtual void Tipo_GasolinaPagination_PageSizeButton_Click(object sender, EventArgs args)
        {
        
            try {
                
            this.DataChanged = true;
      
            this.PageSize = Convert.ToInt32(this.Tipo_GasolinaPagination.PageSize.Text);
      
            this.PageIndex = Convert.ToInt32(this.Tipo_GasolinaPagination.CurrentPage.Text) - 1;
      
            } catch (Exception ex) {
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
    
            }
    
        }
        
        // Event handler for Tipo_GasolinaPaginationImageButton .
        public virtual void Tipo_GasolinaPagination_PreviousPage_Click(object sender, ImageClickEventArgs args)
        {
        
            try {
                
            if (this.PageIndex > 0) {
                this.PageIndex -= 1;
                this.DataChanged = true;
            }
      
            } catch (Exception ex) {
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
    
            }
    
        }
        

        // Generate the event handling functions for sorting events.
        
        public virtual void descripcionLabel_Click(object sender, EventArgs args)
        {
            //Sorts by descripcion when clicked.
              
            // Get previous sorting state for descripcion.
        
            OrderByItem sd = this.CurrentSortOrder.Find(Tipo_GasolinaTable.descripcion);
            if (sd == null || (this.CurrentSortOrder.Items != null && this.CurrentSortOrder.Items.Length > 1)) {
                // First time sort, so add sort order for descripcion.
                this.CurrentSortOrder.Reset();
                this.CurrentSortOrder.Add(Tipo_GasolinaTable.descripcion, OrderByItem.OrderDir.Asc);
            } else {
                // Previously sorted by descripcion, so just reverse.
                sd.Reverse();
            }
        

            // Setting the DataChanged to true results in the page being refreshed with
            // the most recent data from the database.  This happens in PreRender event
            // based on the current sort, search and filter criteria.
            this.DataChanged = true;
              
        }
            
        public virtual void Nombre_Tipo_GasolinaLabel_Click(object sender, EventArgs args)
        {
            //Sorts by Nombre_Tipo_Gasolina when clicked.
              
            // Get previous sorting state for Nombre_Tipo_Gasolina.
        
            OrderByItem sd = this.CurrentSortOrder.Find(Tipo_GasolinaTable.Nombre_Tipo_Gasolina);
            if (sd == null || (this.CurrentSortOrder.Items != null && this.CurrentSortOrder.Items.Length > 1)) {
                // First time sort, so add sort order for Nombre_Tipo_Gasolina.
                this.CurrentSortOrder.Reset();
                this.CurrentSortOrder.Add(Tipo_GasolinaTable.Nombre_Tipo_Gasolina, OrderByItem.OrderDir.Asc);
            } else {
                // Previously sorted by Nombre_Tipo_Gasolina, so just reverse.
                sd.Reverse();
            }
        

            // Setting the DataChanged to true results in the page being refreshed with
            // the most recent data from the database.  This happens in PreRender event
            // based on the current sort, search and filter criteria.
            this.DataChanged = true;
              
        }
            

        // Generate the event handling functions for button events.
        
        // Event handler for ImageButton .
        public virtual void Tipo_GasolinaAddButton_Click(object sender, ImageClickEventArgs args)
        {
        
            try {
                // Enclose all database retrieval/update code within a Transaction boundary
                DbUtils.StartTransaction();
                
            this.AddNewRecord = 1;
            this.DataChanged = true;
      
            } catch (Exception ex) {
                  // Upon error, rollback the transaction
                  this.Page.RollBackTransaction(sender);
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
                DbUtils.EndTransaction();
            }
    
        }
        
        // Event handler for ImageButton .
        public virtual void Tipo_GasolinaDeleteButton_Click(object sender, ImageClickEventArgs args)
        {
        
            try {
                // Enclose all database retrieval/update code within a Transaction boundary
                DbUtils.StartTransaction();
                
            if (!this.Page.IsPageRefresh) {
        
                this.DeleteSelectedRecords(true);
                this.SetFormulaControls();
          
            }
      
            } catch (Exception ex) {
                  // Upon error, rollback the transaction
                  this.Page.RollBackTransaction(sender);
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
                DbUtils.EndTransaction();
            }
    
        }
        
        // Event handler for ImageButton .
        public virtual void Tipo_GasolinaSaveButton_Click(object sender, ImageClickEventArgs args)
        {
        
            try {
                // Enclose all database retrieval/update code within a Transaction boundary
                DbUtils.StartTransaction();
                
        
              if (!this.Page.IsPageRefresh)
              {
                  this.SaveData();
              }

                    this.Page.CommitTransaction(sender);
          // Set IsNewRecord to False for all records - since everything has been saved and is no longer "new"
           
                foreach (Tipo_GasolinaTableControlRow recCtl in this.GetRecordControls()){
                     
                    recCtl.IsNewRecord = false;
                }
      
          // Set DeletedRecordsIds to Nothing since we have deleted all pending deletes.
          
                this.DeletedRecordIds = null;
            
            } catch (Exception ex) {
                  // Upon error, rollback the transaction
                  this.Page.RollBackTransaction(sender);
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
                DbUtils.EndTransaction();
            }
    
        }
        
        // event handler for Button with Layout
        public virtual void Tipo_GasolinaSearchButton_Click(object sender, EventArgs args)
        {
              
            try {
                
            this.DataChanged = true;
      
            } catch (Exception ex) {
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
    
            }
    
        }
            


        // Generate the event handling functions for filter and search events.
        
        // event handler for FieldFilter
        protected virtual void descripcionFilter_SelectedIndexChanged(object sender, EventArgs args)
        {
            // Setting the DataChanged to True results in the page being refreshed with
            // the most recent data from the database.  This happens in PreRender event
            // based on the current sort, search and filter criteria.
            this.DataChanged = true;
            
           				
        }
            
        // event handler for FieldFilter
        protected virtual void Nombre_Tipo_GasolinaFilter_SelectedIndexChanged(object sender, EventArgs args)
        {
            // Setting the DataChanged to True results in the page being refreshed with
            // the most recent data from the database.  This happens in PreRender event
            // based on the current sort, search and filter criteria.
            this.DataChanged = true;
            
           				
        }
            
      
        // Generate the event handling functions for others
        	  

        private System.Collections.Generic.List<Hashtable> _UIData = new System.Collections.Generic.List<Hashtable>();
        public System.Collections.Generic.List<Hashtable> UIData {
            get {
                return this._UIData;
            }
            set {
                this._UIData = value;
            }
        }
        
        // verify the processing details for these properties
        private int _PageSize;
        public int PageSize {
            get {
                return this._PageSize;
            }
            set {
                this._PageSize = value;
            }
        }

        private int _PageIndex;
        public int PageIndex {
            get {
                // _PageSize return (the PageIndex);
                return this._PageIndex;
            }
            set {
                this._PageIndex = value;
            }
        }

        private int _TotalRecords;
        public int TotalRecords {
            get {
                return (this._TotalRecords);
            }
            set {
                if (this.PageSize > 0) {
                    this.TotalPages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(value) / Convert.ToDouble(this.PageSize)));
                }
                this._TotalRecords = value;
            }
        }

        private int _TotalPages;
        public int TotalPages {
            get {
                return this._TotalPages;
            }
            set {
                this._TotalPages = value;
            }
        }

        private bool _DisplayLastPage;
        public bool DisplayLastPage {
            get {
                return this._DisplayLastPage;
            }
            set {
                this._DisplayLastPage = value;
            }
        }

        private bool _DataChanged = false;
        public bool DataChanged {
            get {
                return this._DataChanged;
            }
            set {
                this._DataChanged = value;
            }
        }

        private bool _ResetData = false;
        public bool ResetData {
            get {
                return this._ResetData;
            }
            set {
                this._ResetData = value;
            }
        }

        private int _AddNewRecord = 0;
        public int AddNewRecord {
            get {
                return this._AddNewRecord;
            }
            set {
                this._AddNewRecord = value;
            }
        }

        
        private OrderBy _CurrentSortOrder = null;
        public OrderBy CurrentSortOrder {
            get {
                return this._CurrentSortOrder;
            }
            set {
                this._CurrentSortOrder = value;
            }
        }
        
        private Tipo_GasolinaRecord[] _DataSource = null;
        public  Tipo_GasolinaRecord[] DataSource {
             
            get {
                return this._DataSource;
            }
            set {
                this._DataSource = value;
            }
        }

#region "Helper Properties"
        
        public System.Web.UI.WebControls.DropDownList descripcionFilter {
            get {
                return (System.Web.UI.WebControls.DropDownList)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "descripcionFilter");
            }
        }
        
        public System.Web.UI.WebControls.LinkButton descripcionLabel {
            get {
                return (System.Web.UI.WebControls.LinkButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "descripcionLabel");
            }
        }
        
        public System.Web.UI.WebControls.Literal descripcionLabel1 {
            get {
                return (System.Web.UI.WebControls.Literal)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "descripcionLabel1");
            }
        }
        
        public System.Web.UI.WebControls.DropDownList Nombre_Tipo_GasolinaFilter {
            get {
                return (System.Web.UI.WebControls.DropDownList)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Nombre_Tipo_GasolinaFilter");
            }
        }
        
        public System.Web.UI.WebControls.LinkButton Nombre_Tipo_GasolinaLabel {
            get {
                return (System.Web.UI.WebControls.LinkButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Nombre_Tipo_GasolinaLabel");
            }
        }
        
        public System.Web.UI.WebControls.Literal Nombre_Tipo_GasolinaLabel1 {
            get {
                return (System.Web.UI.WebControls.Literal)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Nombre_Tipo_GasolinaLabel1");
            }
        }
        
        public System.Web.UI.WebControls.ImageButton Tipo_GasolinaAddButton {
            get {
                return (System.Web.UI.WebControls.ImageButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Tipo_GasolinaAddButton");
            }
        }
        
        public System.Web.UI.WebControls.ImageButton Tipo_GasolinaDeleteButton {
            get {
                return (System.Web.UI.WebControls.ImageButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Tipo_GasolinaDeleteButton");
            }
        }
        
        public EnGasAdoAPP.UI.IPaginationMedium Tipo_GasolinaPagination {
            get {
                return (EnGasAdoAPP.UI.IPaginationMedium)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Tipo_GasolinaPagination");
            }
        }
        
        public System.Web.UI.WebControls.ImageButton Tipo_GasolinaSaveButton {
            get {
                return (System.Web.UI.WebControls.ImageButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Tipo_GasolinaSaveButton");
            }
        }
        
        public System.Web.UI.WebControls.TextBox Tipo_GasolinaSearch {
            get {
                return (System.Web.UI.WebControls.TextBox)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Tipo_GasolinaSearch");
            }
        }
        
        public EnGasAdoAPP.UI.IThemeButton Tipo_GasolinaSearchButton {
            get {
                return (EnGasAdoAPP.UI.IThemeButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Tipo_GasolinaSearchButton");
            }
        }
        
        public System.Web.UI.WebControls.Literal Tipo_GasolinaTitle {
            get {
                return (System.Web.UI.WebControls.Literal)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Tipo_GasolinaTitle");
            }
        }
        
        public System.Web.UI.WebControls.CheckBox Tipo_GasolinaToggleAll {
            get {
                return (System.Web.UI.WebControls.CheckBox)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "Tipo_GasolinaToggleAll");
            }
        }
        
#endregion

#region "Helper Functions"
        
        public override string ModifyRedirectUrl(string url, string arg, bool bEncrypt)
        {
            return this.Page.EvaluateExpressions(url, arg, bEncrypt, this);
        }
        
        public override string EvaluateExpressions(string url, string arg, bool bEncrypt)
        {
            bool needToProcess = AreAnyUrlParametersForMe(url, arg);
            if (needToProcess) {
                Tipo_GasolinaTableControlRow recCtl = this.GetSelectedRecordControl();
                if (recCtl == null && url.IndexOf("{") >= 0) {
                    // Localization.
                    throw new Exception(Page.GetResourceValue("Err:NoRecSelected", "EnGasAdoAPP"));
                }

        Tipo_GasolinaRecord rec = null;
                if (recCtl != null) {
                    rec = recCtl.GetRecord();
                }
                return EvaluateExpressions(url, arg, rec, bEncrypt);
             
            }
            return url;
        }
          
        public virtual int GetSelectedRecordIndex()
        {
            int counter = 0;
            foreach (Tipo_GasolinaTableControlRow recControl in this.GetRecordControls())
            {
                if (recControl.Tipo_GasolinaRecordRowSelection.Checked) {
                    return counter;
                }
                counter += 1;
            }
            return -1;
        }
        
        public virtual Tipo_GasolinaTableControlRow GetSelectedRecordControl()
        {
        Tipo_GasolinaTableControlRow[] selectedList = this.GetSelectedRecordControls();
            if (selectedList.Length == 0) {
            return null;
            }
            return selectedList[0];
          
        }

        public virtual Tipo_GasolinaTableControlRow[] GetSelectedRecordControls()
        {
        
            ArrayList selectedList = new ArrayList(25);
            foreach (Tipo_GasolinaTableControlRow recControl in this.GetRecordControls())
            {
                if (recControl.Tipo_GasolinaRecordRowSelection.Checked) {
                    selectedList.Add(recControl);
                }
            }
            return (Tipo_GasolinaTableControlRow[])(selectedList.ToArray(Type.GetType("EnGasAdoAPP.UI.Controls.EditTipo_GasolinaTable.Tipo_GasolinaTableControlRow")));
          
        }

        public virtual void DeleteSelectedRecords(bool deferDeletion)
        {
            Tipo_GasolinaTableControlRow[] recordList = this.GetSelectedRecordControls();
            if (recordList.Length == 0) {
                // Localization.
                throw new Exception(Page.GetResourceValue("Err:NoRecSelected", "EnGasAdoAPP"));
            }
            
            foreach (Tipo_GasolinaTableControlRow recCtl in recordList)
            {
                if (deferDeletion) {
                    if (!recCtl.IsNewRecord) {
                
                        this.AddToDeletedRecordIds(recCtl);
                  
                    }
                    recCtl.Visible = false;
                
                    recCtl.Tipo_GasolinaRecordRowSelection.Checked = false;
                
                } else {
                
                    recCtl.Delete();
                    // Setting the DataChanged to True results in the page being refreshed with
                    // the most recent data from the database.  This happens in PreRender event
                    // based on the current sort, search and filter criteria.
                    this.DataChanged = true;
                    this.ResetData = true;
                  
                }
            }
        }

        public Tipo_GasolinaTableControlRow[] GetRecordControls()
        {
            ArrayList recordList = new ArrayList();
            System.Web.UI.WebControls.Repeater rep = (System.Web.UI.WebControls.Repeater)this.FindControl("Tipo_GasolinaTableControlRepeater");
            if (rep == null){return null;}
            foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items)
            {
                Tipo_GasolinaTableControlRow recControl = (Tipo_GasolinaTableControlRow)repItem.FindControl("Tipo_GasolinaTableControlRow");
                recordList.Add(recControl);
            }

            return (Tipo_GasolinaTableControlRow[])recordList.ToArray(Type.GetType("EnGasAdoAPP.UI.Controls.EditTipo_GasolinaTable.Tipo_GasolinaTableControlRow"));
        }

        public new BaseApplicationPage Page 
        {
            get {
                return ((BaseApplicationPage)base.Page);
            }
        }
#endregion

    

    }
  

#endregion
    
  
}

  